package com.study.study.quartz;

import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 名称：HelloJob
 * 功能描述：
 *
 * @author: zhang
 * @version: 3.0
 * @date: 2019-09-08 22:01:37
 * @since 1.8
 **/

/**
 * 更新jobData
 *
 * @author zhang
 */
@PersistJobDataAfterExecution
/**
 *设置job不并行
 */
@DisallowConcurrentExecution
public class HelloJob implements Job {

    private static final Logger LOG = LoggerFactory.getLogger(HelloJob.class);

    public HelloJob() {
        LOG.info("construct!");
    }

    private static String print() {
        return "5";
    }

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        JobKey key = context.getJobDetail().getKey();

        JobDataMap dataMap = context.getJobDetail().getJobDataMap();


        LOG.info(dataMap.getString("task") + key.getName());
        dataMap.put("task", "libai");
        try {
            LOG.info("Hello world!" + print());
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
